package andrei.mower2.business.output;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import andrei.mower2.business.MowerDriveResult;
import andrei.mower2.main.i18n.MessageUtils;

public class FileOutputter implements MowerDriveResultOutputter {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(FileOutputter.class);

	private  static final String OUTPUT_FILE_SUFFIX = ".result";
	
	private final PrintWriter out;
	
	public FileOutputter(String inputFileLocation) throws FileNotFoundException {
		File inputFile = new File(inputFileLocation);
		File outputFile = new File(inputFile.getParentFile(), inputFile.getName() + OUTPUT_FILE_SUFFIX);
		out = new PrintWriter(outputFile);
		LOGGER.info(MessageUtils.getMessage("info.io.reportFileLocation", outputFile.getAbsolutePath()));
	}
	
	@Override
	public void output(MowerDriveResult result) {
		out.println(result.toOutputString());
	}

	@Override
	public void close() {
		out.close();
		
	}

}
